package com.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.test.bean.User;
import com.test.service.UserService;


@RestController//与@Controller区别在于自带@ResponseBody所有返回值都当字符串,不做跳转处理
@RequestMapping("/user")  
@EnableAutoConfiguration
public class UserController {
	
	@Autowired//bytype根据类型注入
	private UserService userService;
//	@Autowired//bytype根据类型注入
//	private User user;

	@RequestMapping("/{id}")  
	public User view(@PathVariable("id") Long id) {  
		userService.test();//可以切入
		User user = userService.getUser(id);
		return user;  
	}
	
	@RequestMapping("/test")//@RestController 无法转发到jsp页面.只返回字符串
	public String welcome() { 
		return "welcome";
	}
	
//	@Bean
//	public User getZS(){
//		User user = new User();  
//		user.setId(1);  
//		user.setName("ZS");
//		return user;
//	}
	
//	@Bean
//	public User getLS(){
//		User user = new User();  
//		user.setId(2);  
//		user.setName("LS");
//		return user;
//	}
	
//	public static void main(String[] args) {
//		SpringApplication.run(UserController.class);
//	}

}
